package com.terrorism.first.server;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.terrorism.first.model.HotOfCategoryModel;
import com.terrorism.sdk.utils.JsonParser;

public class HotOfCategoryConnect {

	public static String result = "result";
	public static String categories = "categorys";
	public static String categoryId ="categoryId";
	public static String categoryName ="categoryName";
	public static String shop1 = "shop1";
	public static String shop2 = "shop2";
	public static String shop3 = "shop3";
	public static String shopId ="shopId";
	public static String shopName = "shopName";
	public static String shopCover = "shopCover";
	public static String shopAvatar = "shopAvatar";
	public static String shopNumOfRate = "shopNumOfRate";
	
	private static JsonParser jsonParser = new JsonParser();

	public static JSONObject getHotOfCategory(Context mContext) {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		JSONObject json = jsonParser.getJSONFromUrl(API.catogoryGet, params);
		return json;
	}

	public static List<HotOfCategoryModel> getHotOfCategoryFromJson( JSONObject jsonObject)
	{
		 List<HotOfCategoryModel> listData = new ArrayList<HotOfCategoryModel>();
		JSONArray listResult;
		try {
			listResult = jsonObject.getJSONArray(HotOfCategoryConnect.categories);
			for(int i = 0; i<listResult.length();i++)
			{
				JSONObject jsonData = listResult.getJSONObject(i);
				JSONObject shop1,shop2,shop3;
				HotOfCategoryModel  temp = new HotOfCategoryModel();
				temp.getCategory().setId(jsonData.getInt(categoryId));
				temp.getCategory().setCategoryName(jsonData.getString(HotOfCategoryConnect.categoryName));
				
				shop1 = jsonData.getJSONObject(HotOfCategoryConnect.shop1);
				temp.getRank1().setId(shop1.getInt(HotOfCategoryConnect.shopId));
				temp.getRank1().setName(shop1.getString(HotOfCategoryConnect.shopName));
				temp.getRank1().setAvartaUrl(shop1.getString(HotOfCategoryConnect.shopAvatar));
				shop2 = jsonData.getJSONObject(HotOfCategoryConnect.shop2);
				temp.getRank2().setId(shop2.getInt(HotOfCategoryConnect.shopId));
				temp.getRank2().setName(shop2.getString(HotOfCategoryConnect.shopName));
				temp.getRank2().setAvartaUrl(shop2.getString(HotOfCategoryConnect.shopAvatar));
				
				shop3 = jsonData.getJSONObject(HotOfCategoryConnect.shop3);
				temp.getRank3().setId(shop3.getInt(HotOfCategoryConnect.shopId));
				temp.getRank3().setName(shop3.getString(HotOfCategoryConnect.shopName));
				temp.getRank3().setAvartaUrl(shop3.getString(HotOfCategoryConnect.shopAvatar));
				listData.add(temp);
				
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
		
		return listData;
	}
}
